package com.dwk.controller;

import com.dwk.config.ConfirmConfig;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 测试发布确认
 */
@RestController
@Slf4j
@RequestMapping("/confirm")
public class ProducerController {
    public static final String CONFIRM_EXCHANGE_NAME = "confirm.exchange";

    @Autowired
    private RabbitTemplate rabbitTemplate;;


    //发消息
    @GetMapping("/sendMessage/{message}")
    public String sendMessage(@PathVariable String message){
        CorrelationData correlationData1=new CorrelationData("1");
        CorrelationData correlationData2=new CorrelationData("2");

        //测试正确的
        rabbitTemplate.convertAndSend(CONFIRM_EXCHANGE_NAME, "key1",message,correlationData1);
        log.info("发送消息内容:{}",message);

        //测试错误的,走备份交换机到报警消息
        rabbitTemplate.convertAndSend(CONFIRM_EXCHANGE_NAME, "key1_test_wrong",message,correlationData2);
        log.info("发送消息内容:{}",message);
        return message;
    }

}
